#include "comm.hpp"

int main()
{
    Init init;
    int shmid = CreateShm();
    char* shmaddr = (char*)shmat(shmid, nullptr, 0);

    // 打开管道文件
    int fd = open(FIFO_FILE, O_RDONLY);
    if (fd < 0)
    {
        log(Fatal, "open error: %s", strerror(errno));
        exit(FIFO_OPEN_ERR);
    }

    struct shmid_ds shmds;
    while (true)
    {
        char ch;
        ssize_t n = read(fd, &ch, sizeof(ch));
        if (n <= 0) break;
        cout << "processb say# " << shmaddr; 

        // shmctl(shmid, IPC_STAT, &shmds);
        // cout << "size: " << shmds.shm_segsz << endl;
        // cout << "nattch: " << shmds.shm_nattch << endl;
        // printf("key: 0x%x\n", shmds.shm_perm.__key);
        // cout << "mode: " << shmds.shm_perm.mode << endl << endl;
        sleep(1);
    }

    shmdt(shmaddr);
    shmctl(shmid, IPC_RMID, nullptr);
    close(fd);
    return 0;
}